package com.tencent.qcloud.tim.uikit.http

import com.manor.common.CommonAppConfig
import com.manor.common.http.HttpCallback
import com.manor.common.http.HttpClient

/**
 * Created by cxf on 2019/2/26.
 */
object TkHttpUtil {
    /**
     * 取消网络请求
     */
    @JvmStatic
    fun cancel(tag: String?) {

        HttpClient.getInstance().cancel(tag)
    }


    /**
     * 创建群
     */
    fun getGroupFMember(id: String, callback: HttpCallback?) {
        HttpClient.getInstance().post("Group.GetFilterFriends", TkHttpConst.GET_GROUP_F_MEMBER)
                .params("uid", CommonAppConfig.getInstance().uid)
                .params("token", CommonAppConfig.getInstance().token)
                .params("group_id", id)
                .execute(callback)
    }


    /**
     * 获取用户之间关系
     */
    fun getUserRelation(toId: String, callback: HttpCallback?) {
        HttpClient.getInstance().post("User.GetRelation", TkHttpConst.GET_RELATION)
                .params("uid", CommonAppConfig.getInstance().uid)
                .params("token", CommonAppConfig.getInstance().token)
                .params("touid", toId)
                .execute(callback)
    }

    /**
     * 设置聊天背景
     * type 1 单聊,2 群聊,3 单对单聊
     */
    fun setIMChatBg(id: String, url: String, callback: HttpCallback?) {
        HttpClient.getInstance().post("Group.SetGroupBg", TkHttpConst.SET_GROUP_BG)
                .params("uid", CommonAppConfig.getInstance().uid)
                .params("token", CommonAppConfig.getInstance().token)
                .params("operation_id", id)
                .params("background", url)
                .params("type", "1")
                .execute(callback)
    }

    /**
     * 获取聊天背景
     * type 1 单聊,2 群聊,3 单对单聊
     */
    fun getIMChatBg(id: String, callback: HttpCallback) {
        HttpClient.getInstance().post("Group.GetGroupBg", TkHttpConst.GET_GROUP_BG)
                .params("uid", CommonAppConfig.getInstance().uid)
                .params("token", CommonAppConfig.getInstance().token)
                .params("operation_id", id)
                .params("type", "1")
                .execute(callback)
    }

    /**
     * 获取好友列表
     */
    fun getFilterFriend(id: String, callback: HttpCallback) {
        HttpClient.getInstance()["Group.GetFilterFriends", TkHttpConst.GET_FILTER_FRIEND]
                .params("uid", CommonAppConfig.getInstance().uid)
                .params("token", CommonAppConfig.getInstance().token)
                .params("group_id", id)
                .execute(callback)
    }



    /**
     * 邀请好友入群
     */
    fun getInviteFriend(groupId: String, toId: String, callback: HttpCallback) {
        HttpClient.getInstance().post("Group.InviteToGroup", TkHttpConst.INVITE_FRIEND)
                .params("uid", CommonAppConfig.getInstance().uid)
                .params("token", CommonAppConfig.getInstance().token)
                .params("group_id", groupId)
                .params("to_uid", toId)
                .execute(callback)
    }


}